package com.jp.vn.main;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.ConnectivityManager;
import android.net.NetworkInfo.State;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

public class BaseActivity extends Activity {

	/*
	 * Hàm kiểm tra kết nối internet
	 */
	public Boolean checkConnection() {
		ConnectivityManager conn = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
		if (conn != null
				&& (conn.getNetworkInfo(1).getState() == State.CONNECTED)
				|| (conn.getNetworkInfo(0).getState() == State.CONNECTED)) {
			return true;
		} else {
			return false;
		}
	}

	public void showDialogScore(Activity context, int time, int rightAns, int wrongAns){
		final Dialog dialog_score = new Dialog(context,android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
		dialog_score.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
				WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
		dialog_score.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
		dialog_score.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
		dialog_score.setContentView(R.layout.dialog_score);
		
		WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
		lp.copyFrom(dialog_score.getWindow().getAttributes());
	    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
	    lp.height = WindowManager.LayoutParams.MATCH_PARENT;
	    dialog_score.show();
	    dialog_score.getWindow().setAttributes(lp);
	    
	    TextView tfThoiGian = (TextView) dialog_score.findViewById(R.id.tfTime);
	    tfThoiGian.setText("Thời gian : "+time + " giây");
	    
	    TextView tfRightAns = (TextView) dialog_score.findViewById(R.id.tfRight);
	    tfRightAns.setText("Đúng : "+rightAns + " câu");
	    
	    TextView tfWrongAns = (TextView) dialog_score.findViewById(R.id.tfWrong);
	    tfWrongAns.setText("Sai : "+wrongAns + " câu");
	    
	    Button btnOk =  (Button) dialog_score.findViewById(R.id.btnOk);
	    btnOk.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				dialog_score.dismiss();
				finish();
			}
		});
		
	}
}
